package com.laowang.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyGoodsCat;
import com.laowang.project.system.service.MyGoodsCatService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 商品分类Controller
 *
 * @author laowang
 * @date 2023-07-20
 */
@Api(tags = "商品分类接口")
@RestController
@RequestMapping("/goodsCat")
public class MyGoodsCatController extends BaseController {

    @Autowired
    private MyGoodsCatService myGoodsCatService;

    @ApiOperation(value = "小程序端 商品分类列表",notes = "")
    @GetMapping("/web/list")
    public AjaxResult weblist() {
        List<MyGoodsCat> list = myGoodsCatService.selectMyGoodsCatList(null);

        return AjaxResult.success("操作成功", list);
    }



    /**
     * 查询商品分类列表
     */
    @ApiOperation(value = "查询商品分类列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:goodsCat:list')")
    @GetMapping("/list")
        public TableDataInfo list(MyGoodsCat myGoodsCat) {
        startPage();
        List<MyGoodsCat> list = myGoodsCatService.selectMyGoodsCatList(myGoodsCat);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
    @ApiOperation(value = "导出商品分类列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:goodsCat:export')")
    @GetMapping("/export")
    public AjaxResult export(MyGoodsCat myGoodsCat) {
        List<MyGoodsCat> list = myGoodsCatService.selectMyGoodsCatList(myGoodsCat);
        ExcelUtil<MyGoodsCat> util = new ExcelUtil<MyGoodsCat>(MyGoodsCat.class);
        return util.exportExcel(list, "goodsCat");
    }

    /**
     * 获取商品分类详细信息
     */
    @ApiOperation(value = "获取商品分类详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:goodsCat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myGoodsCatService.selectMyGoodsCatById(id));
    }

    /**
     * 新增商品分类
     */
    @ApiOperation(value = "新增商品分类",notes = "")
    @PreAuthorize("@ss.hasPermi('my:goodsCat:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MyGoodsCat myGoodsCat) {
        return toAjax(myGoodsCatService.insertMyGoodsCat(myGoodsCat));
    }

    /**
     * 修改商品分类
     */
    @ApiOperation(value = "修改商品分类",notes = "")
    @PreAuthorize("@ss.hasPermi('my:goodsCat:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MyGoodsCat myGoodsCat) {
        return toAjax(myGoodsCatService.updateMyGoodsCat(myGoodsCat));
    }

    /**
     * 删除商品分类
     */
    @ApiOperation(value = "删除商品分类",notes = "")
    @PreAuthorize("@ss.hasPermi('my:goodsCat:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myGoodsCatService.deleteMyGoodsCatByIds(ids));
    }
}
